package com.cloud.util;

import java.util.UUID;

/**
 * 1Cloud1
 * @author Administrator
 * @since 2015-12-16
 * @version 1.0
 */
public class TokenUtil {

	public static Boolean tokenVerification(String uid, String token) {
		try {
			String str2 = token.substring(token.length() - 9);
			String md5str = token.substring(7, token.length() - 9);
			String checkToken = CommUtil.MD5("lcloud1:" + uid + ":" + str2);
			return md5str.equalsIgnoreCase(checkToken);
		} catch (Exception e) {
			return false;
		}
	}

	public static String tokenProduce(String uid) {
		String uuid = (UUID.randomUUID().toString()).replace("-", "");
		String str1 = uuid.substring(0, 7);
		String str2 = uuid.substring(uuid.length() - 9, uuid.length());
		return str1 + CommUtil.MD5("lcloud1:" + uid + ":" + str2) + str2;
	}

	public static void main(String[] args) {
		String uid = "+8613800138000";
		String token = tokenProduce(uid);
		System.out.println("token:" + token);
		Boolean falg = tokenVerification(uid, token);
		System.out.println("check token flag:" + falg);
	}

}
